<template>
  <div>
    <!--    默认打开和默认活跃-->
    <el-menu
      :default-active="path"
      :default-openeds="[1]"
      class="el-menu-vertical-demo"
      style="width: 200px;min-height:calc(100vh - 50px)"
      @open="handleOpen"
      @close="handleClose"

    >
      <el-submenu index="1" v-if="this.user.roles===1">
        <template slot="title">
          <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></el-avatar>
          <span>系统管理</span>
        </template>

        <el-menu-item-group>
          <el-menu-item index="/user" @click="goHome">用户管理</el-menu-item>
        </el-menu-item-group>

        <el-menu-item-group>
          <el-menu-item index="/book" @click="goData">书籍管理</el-menu-item>
        </el-menu-item-group>
      </el-submenu>


      <el-submenu index="2">
        <template slot="title">
          <i class="el-icon-news"></i>
          <span>新闻管理</span>
        </template>

        <el-menu-item-group>
          <el-menu-item index="/news" @click="$router.push('/news')">新闻</el-menu-item>
        </el-menu-item-group>

      </el-submenu>


    </el-menu>
  </div>
</template>

<script>
import request from "../unitls/request";

export default {
  name: "Aside",
  created() {
    this.user = JSON.parse(sessionStorage.getItem("user"));
    request.get("/api/user/own", {
      params: {
        id: this.user.id
      }
    }).then(success => {
      if (success.code === '0') {
        this.user =success.data;
      }

    })
  },
  methods: {
    handleOpen() {
      console.log('handleOpen !!')
    },
    handleClose() {
      console.log('handleClose !!')
    },
    goHome() {
      this.$router.replace('/');
    },
    goData() {
      this.$router.replace('/book');
    }
  },
  data() {
    return {
      path: this.$route.path, //设置高亮菜单
      user: {}
    }
  }
}
</script>

<style scoped>

</style>
